//
//  NSDate+Handler.m
//  PPCheckTool
//
//  Created by BenJim on 2019/4/5.
//

#import "NSDate+Handler.h"

@implementation NSDate (Handler)


+ (BOOL)resuleWith:(NSString *)y1 m1:(NSString *)m1 d1:(NSString *)d1 y2:(NSString *)y2 m2:(NSString *)m2 d2:(NSString *)d2{
    if ([NSDate handlerStrData:[[[NSString stringWithFormat:@"%@ %@ %@",y1,m1,d1] stringByReplacingOccurrencesOfString:@" " withString:@"-"] stringByAppendingString:@" 00:00:00"] WithDate:[[[NSString stringWithFormat:@"%@ %@ %@",y2,m2,d2] stringByReplacingOccurrencesOfString:@" " withString:@"-"] stringByAppendingString:@" 00:00:00"]] >= 1) {
        return NO;
    }else{
        return YES;
    }
}

+ (NSInteger)handlerStrData:(NSString *)date1 WithDate:(NSString *)date2
{
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    if (date1.length > 10 && date2.length > 10) {
        [df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    }else{
        [df setDateFormat:@"yyyy-MM-dd"];
    }
    NSDate *dt1 = [df dateFromString:date1];
    NSDate *dt2 = [df dateFromString:date2];
    return  [self compareData:dt1 WithDate:dt2];
}

+ (NSInteger)compareData:(NSDate *)date1 WithDate:(NSDate *)date2
{
    NSComparisonResult result = [date1 compare:date2];
    if (result == NSOrderedAscending) {
        return 1 ;
    }else if (result == NSOrderedSame){
        return 0;
    }else if (result == NSOrderedDescending){
        return -1;
    }
    return 0;
}

+ (NSArray *)getResults{
    NSString * str = [NSDate getCurrentTimes];
    NSArray *array = [str componentsSeparatedByString:@"-"];
    return array;
    
}

+(NSString*)getCurrentTimes{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"YYYY-MM-dd"];
    NSDate *datenow = [NSDate date];
    NSString *currentTimeString = [formatter stringFromDate:datenow];
    NSLog(@"currentTimeString =  %@",currentTimeString);
    return currentTimeString;
    
}


@end
